#get the command line arguements
args=(commandArgs(TRUE)); for(i in 1:length(args)) { eval(parse(text=args[[i]])) }

library(SDMTools)

wd='/home/ctbccr/Ramona/MoreSubstr/old/';setwd(wd) #define your working directory; set working directory

base.asc = read.asc.gz('/home/jc165798/Climate/CIAS/Australia/1km/baseline.76to05/base.asc.gz') #read in the base asc file
pos = read.csv('/home/jc165798/Climate/CIAS/Australia/1km/baseline.76to05/base.positions.csv',as.is=TRUE) #read in the position files


tasc=read.asc(tfile)
	tname=strsplit(tfile,'\\.')[[1]][1]

	pos[,5] = extract.data(cbind(pos$lon,pos$lat),tasc)   #extract the data from the ascii and append to pos file

	#create new asciis
	newasc=base.asc; newasc[cbind(pos$row,pos$col)]=pos[,5] #bind pos data to base.asc
	write.asc(newasc,paste('/home/ctbccr/Ramona/MoreSubstr/new/',tname,'.new.asc',sep=''))
